<template>
  <el-dialog
    :title="!dataForm.id ? '' : '未通过原因'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">

    <el-form-item label="菜品ID" prop="foodId" v-show="false">
      <el-input v-model="dataForm.foodId" placeholder="菜品ID"></el-input>
    </el-form-item>
    <el-form-item label="补充原因" prop="auditInfo">
      <el-input v-model="dataForm.auditInfo" placeholder="补充原因"></el-input>
    </el-form-item>
    <el-form-item>
      <el-checkbox-group v-model="list">
        <el-checkbox label="菜品照片不合格" ></el-checkbox>
        <el-checkbox label="菜品描述不合法" ></el-checkbox>
        <el-checkbox label="菜品名称不合法" ></el-checkbox>
      </el-checkbox-group>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { auditInfo } from '../../../validate.js'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          merchantId: '',
          foodId: '',
          auditState: '',
          gmtCreate: '',
          auditInfo: '',
          gmtModified: ''
        },
        list: [],
        dataRule: {
          foodId: [
            { required: true, message: '菜品ID不能为空', trigger: 'blur' }
          ],
          auditInfo: [
            { required: true, validator: auditInfo, trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/diancan/shopfoodaudit/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.foodId = data.shopFoodAudit.foodId
              }
            })
          }
        })
      },
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/diancan/shopfoodaudit/AuditFood'),
              method: 'get',
              params: this.$http.adornParams({
                'foodId': this.dataForm.foodId,
                'aduitInfo': this.list.toString() + this.dataForm.auditInfo,
                'auditState': 2,
                'isUpper': 0
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$store.commit('common/updateIsOpen')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
